<?php
namespace Taxx\UserBundle\Forms;

use Taxx\KernelBundle\Model\FormBuilder\FormBuilder;
use Taxx\KernelBundle\Model\Utils\JsonTranslator;
use Taxx\KernelBundle\Model\Utils\PublicFileRegistry;
use Doctrine\ORM\EntityManager;

class RegisterForm 
{
    private $builder;
    
    public function __construct(EntityManager $em, $language) 
    {
        $translations = JsonTranslator::parseTranslationFile(PublicFileRegistry::getFilePath("user_translations"));
        $labels = $translations['form_labels'][$language];
        $this->builder = new FormBuilder();
        $this->builder->setLegend($labels['register']);
        $this->builder->addInputField('register_username', $labels['username'], array('name'=>'username', 'type' => 'text'));
        $this->builder->addInputField('register_email', $labels['email'], array('name'=>'email', 'type' => 'text'));
        $this->builder->addInputField('register_password', $labels['password'], array('name'=>'password', 'type' => 'password'));
        $this->builder->addInputField('register_confirm_password', $labels['confirm_password'], array('name'=>'confirm_password', 'type' => 'password'));
        $language_entities = $em->getRepository('TaxxKernelBundle:Language')->findAll();
        $languages = array();
        foreach($language_entities as $le)
            $languages[''.$le->getId()] = $le->getName();
        $this->builder->addSelectField('register_language', $labels['language'], $languages, null, array('name'=>'language'));
        $this->builder->addButton('register_btn', $labels['register_btn'], array('type'=>'button', 'onclick'=>'checkRegisterForm(\''.$language.'\')'));
    }
    
    public function getForm($action)
    {
        return $this->builder->getForm('registerForm', array('action'=>$action, 'method'=>'post'));
    }
}

?>
